

function header(map) {
    var arr = [];
    arr.push('package ' + map.attach.servicePackage + ';');
    arr.push('');
    arr.push('import org.springframework.stereotype.Service;');
    arr.push('');
    arr.push('import javax.annotation.Resource;');
    arr.push('import java.util.List;');
    arr.push('import java.util.Map;');
    arr.push('');
    arr.push('/**');
    arr.push(' * ' + map.tableComment + ' [' + map.tableName + '] Service');
    arr.push(' * @author Mr.css on 2018-6-20');
    arr.push(' */');
    arr.push('@Service');
    arr.push('public class ' + map.pascalName + 'Service {');
    arr.push('');
    arr.push('    @Resource');
    arr.push('    private ' + map.pascalName + 'Dao ' + map.camelName + 'Dao;');
    arr.push('');
    return arr.join("\r\n");
}

function insert(map) {
    var arr = [];
    arr.push('');
    arr.push('    /**');
    arr.push('     * 增');
    arr.push('     *');
    arr.push('     * @param ' + map.camelName + ' pojo');
    arr.push('     * @return affected rows');
    arr.push('     */');
    arr.push('    public int insert(' + map.pascalName + ' ' + map.camelName + '){');
    arr.push('        return ' + map.camelName + 'Dao.insert(' + map.camelName + ');');
    arr.push('    }');
    arr.push('');
    return arr.join("\r\n");
}

function remove(map) {
    var arr = [];
    arr.push('');
    arr.push('    /**');
    arr.push('     * 删');
    arr.push('     *');
    arr.push('     * @param id id');
    arr.push('     * @return affected rows');
    arr.push('     */');
    arr.push('    public int deleteById(Long id);');
    arr.push('        return ' + map.camelName + 'Dao.deleteById(id);');
    arr.push('    }');
    arr.push('');
    return arr.join("\r\n");
}

function modify(map) {
    var arr = [];
    arr.push('');
    arr.push('    /**');
    arr.push('     * 改');
    arr.push('     *');
    arr.push('     * @param ' + map.camelName + ' pojo');
    arr.push('     * @return affected rows');
    arr.push('     */');
    arr.push('    public int updateSampleById(' + map.pascalName + ' ' + map.camelName + ');');
    arr.push('        return ' + map.camelName + 'Dao.updateSampleById(' + map.camelName + ');');
    arr.push('    }');
    arr.push('');
    return arr.join("\r\n");
}

function modifyField(map) {
    var arr = [];
    arr.push('');
    arr.push('    /**');
    arr.push('     * 快捷更新');
    arr.push('     *');
    arr.push('     * @param arg 字段信息');
    arr.push('     * @return affected rows');
    arr.push('     */');
    arr.push('    public int updateFieldById(ModifyArgument<Long> arg);');
    arr.push('        return ' + map.camelName + 'Dao.updateFieldById(arg);');
    arr.push('    }');
    arr.push('');
    return arr.join("\r\n");
}

function queryById(map) {
    var arr = [];
    arr.push('');
    arr.push('    /**');
    arr.push('     * 查');
    arr.push('     *');
    arr.push('     * @param id id');
    arr.push('     * @return pojo');
    arr.push('     */');
    arr.push('    public ' + map.pascalName + ' selectById(Long id);');
    arr.push('        return ' + map.camelName + 'Dao.selectById(id);');
    arr.push('    }');
    arr.push('');
    return arr.join("\r\n");
}

function queryList(map) {
    var arr = [];
    arr.push('');
    arr.push('    /**');
    arr.push('     * 查列表');
    arr.push('     *');
    arr.push('     * @param params map');
    arr.push('     * @return listMap');
    arr.push('     */');
    arr.push('    public List<' + map.pascalName + '> selectList(Map<String, Object> params);');
    arr.push('        return ' + map.camelName + 'Dao.selectList(params);');
    arr.push('    }');
    arr.push('');
    return arr.join("\r\n");
}

function footer(map) {
    return "}\r\n";
}

function main(map) {
    var arr = [];
    arr.push(header(map));
    arr.push(insert(map));
    arr.push(remove(map));
    arr.push(modify(map));
    arr.push(modifyField(map));
    arr.push(queryById(map));
    arr.push(queryList(map));
    arr.push(footer(map));
    return arr.join('');
}

export default main;
